package leetcode.code1338;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int minSetSize(int[] arr) {
		int len = arr.length;
		Integer[] map = new Integer[(int) 1e5 + 1];
		Arrays.fill(map, 0);
		for (int num : arr) {
			map[num]++;
		}
		Arrays.sort(map, (a, b) -> b - a);
		int sum = 0;
		for (int i = 0; i < map.length; i++) {
			sum += map[i];
			if (sum >= len / 2) {
				return i + 1;
			}
		}
		return 0;
	}

	@Override
	public void debug4() {
		H.compare(2, this.minSetSize(H.str2array3("[3,3,3,3,5,5,5,2,2,7]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
